/**
 * 
 */
package co.fitstart.entity.user.profile;

import java.beans.Transient;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;

import co.fitstart.entity.reference.Country;

/**
 * @author Leo
 * @author lute
 * 
 */
public class UserProfile {

    /** 用户昵称 - 初始值来自微信 */
    private String nickname;

    /** 用户头像 - 初始值来自于微信 */
    private String avatar;

    /** 国 */
    private String country;

    /** 省 */
    private String province;

    /** 市 */
    private String region;

    /** 区 */
    private String district;

    /** 地址 */
    private String address;

    /** 出生年月日 YYYY-MM-DD */
    @Type(type = "date")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    /** 是否已婚 */
    private Boolean marriage;

    /** 是否有子女 */
    private Boolean haveKids;

    /** 爱好 */
    private String hobby;

    /** 紧急联系方式 */
    private String emergency;

    /**
     * Default constructor
     */
    public UserProfile() {

    }

    /**
     * @param nickname
     * @param avatar
     */
    public UserProfile(String nickname, String avatar) {
        this.nickname = nickname;
        this.avatar = avatar;
    }

    /**
     * 
     * @return
     */
    public Map<String, Object> describe() {

        Map<String, Object> result = new LinkedHashMap<String, Object>();

        result.put("countryDisplay", this.getCountry());
        result.put("countryValue", Country.aliasOf(this.getCountry()));
        String prdValue = StringUtils.replace(this.getPrd(), ",", "").trim();
        result.put("prdValue", prdValue);

        return result;
    }

    /**
     * 
     * @param country
     * @param province
     * @param region
     * @param district
     * @param address
     * @return
     */
    public UserProfile editProfile(String country, String province, String region, String district, String address) {
        this.country = country;
        this.province = province;
        this.region = region;
        this.district = district;
        this.address = address;
        return this;
    }

    /**
     * 
     * @param userProfile
     * @return
     */
    public UserProfile editProfile(UserProfile userProfile) {
        this.nickname = userProfile.getNickname();
        this.region = userProfile.getRegion();
        this.country = userProfile.getCountry();
        this.province = userProfile.getProvince();
        this.region = userProfile.getRegion();
        this.district = userProfile.getDistrict();

        return this;
    }

    /**
     * 
     * @param nickname
     * @param avatar
     * @return
     */
    public UserProfile edit(String nickname, String avatar) {
        this.nickname = nickname;
        this.avatar = avatar;

        return this;
    }

    /**
     * 
     * @param country
     * @param province
     * @param region
     * @param district
     * @return
     */
    public UserProfile editRegion(Country country, String province, String region, String district) {
        this.country = country == null ? null : country.getDescription();
        this.province = province;
        this.region = region;
        this.district = district;
        return this;
    }

    /**
     * 
     * @param province
     * @param region
     * @param district
     * @return
     */
    public UserProfile editRegion(String province, String region, String district) {
        this.province = province;
        this.region = region;
        this.district = district;
        return this;
    }

    /**
     * 
     * @param birthday
     * @return
     */
    public UserProfile editBirthday(Date birthday) {
        this.birthday = birthday;
        return this;
    }

    /**
     * 
     * @param address
     * @return
     */
    public UserProfile editAddress(String address) {
        this.address = address;
        return this;
    }

    /**
     * @return
     */
    @Transient
    public String getPrd() {

        if (StringUtils.isEmpty(this.province)) { // empty province
            return "";

        } else if (org.apache.commons.lang3.StringUtils.equalsIgnoreCase(this.province, this.region)) { // same province
                                                                                                        // & city
            return this.region + "," + this.district + ",";

        } else { // normal
            return this.province + "," + this.region + "," + this.district;
        }
    }

    /**
     * @return the nickname
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * @return the country
     */
    public String getCountry() {
        return country;
    }

    /**
     * @return the province
     */
    public String getProvince() {
        return province;
    }

    /**
     * @return the region
     */
    public String getRegion() {
        return region;
    }

    /**
     * @return the district
     */
    public String getDistrict() {
        return district;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @return the birthday
     */
    public Date getBirthday() {
        return birthday;
    }

    /**
     * @return the marriage
     */
    public Boolean getMarriage() {
        return marriage;
    }

    /**
     * @return the haveKids
     */
    public Boolean getHaveKids() {
        return haveKids;
    }

    /**
     * @return the hobby
     */
    public String getHobby() {
        return hobby;
    }

    /**
     * @return the emergency
     */
    public String getEmergency() {
        return emergency;
    }

    /**
     * @param nickname
     *            the nickname to set
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @param avatar
     *            the avatar to set
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * @param country
     *            the country to set
     */
    public void setCountry(String country) {
        this.country = country;
    }

    /**
     * @param province
     *            the province to set
     */
    public void setProvince(String province) {
        this.province = province;
    }

    /**
     * @param region
     *            the region to set
     */
    public void setRegion(String region) {
        this.region = region;
    }

    /**
     * @param district
     *            the district to set
     */
    public void setDistrict(String district) {
        this.district = district;
    }

    /**
     * @param address
     *            the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @param birthday
     *            the birthday to set
     */
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    /**
     * @param marriage
     *            the marriage to set
     */
    public void setMarriage(Boolean marriage) {
        this.marriage = marriage;
    }

    /**
     * @param haveKids
     *            the haveKids to set
     */
    public void setHaveKids(Boolean haveKids) {
        this.haveKids = haveKids;
    }

    /**
     * @param hobby
     *            the hobby to set
     */
    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    /**
     * @param emergency
     *            the emergency to set
     */
    public void setEmergency(String emergency) {
        this.emergency = emergency;
    }

}
